package com.cancan.resultreturn.result1.base;

import com.cancan.resultreturn.result1.CommonResponse;
import com.cancan.resultreturn.result1.enums.ResponseCodeEnum;

/**
 * 基类
 * @author cancan
 */
public class BaseController {

    /**
     * 默认成功返回带参数
     * @param data
     * @return
     */
    protected <T> CommonResponse<T> responseSuccess(T data) {
        CommonResponse<T> restResult = new CommonResponse<>(ResponseCodeEnum.SUCCESS);
        restResult.setData(data);
        return restResult;
    }

    /**
     * 默认成功返回
     * @return
     */
    protected <T> CommonResponse<T> responseSuccess() {
        CommonResponse<T> restResult = new CommonResponse<>(ResponseCodeEnum.SUCCESS);
        return restResult;
    }

    /**
     * 默认失败返回带参数
     * @param data
     * @return
     */
    protected <T> CommonResponse<T> responseFailed(String code, String message, T data) {
        CommonResponse<T> restResult = new CommonResponse<>(code, message);
        restResult.setData(data);
        return restResult;
    }

    /**
     * 默认失败返回
     * @return
     */
    protected <T> CommonResponse<T> responseFailed(String code, String message) {
        CommonResponse<T> restResult = new CommonResponse<>(code, message);
        return restResult;
    }

    /**
     * 默认失败返回
     * @return
     */
    protected <T> CommonResponse<T> responseFailed(ResponseCodeEnum responseCodeEnum) {
        CommonResponse<T> restResult = new CommonResponse<>(responseCodeEnum);
        return restResult;
    }

    /**
     * 默认失败返回
     * @return
     */
    protected <T> CommonResponse<T> responseFailed(ResponseCodeEnum responseCodeEnum, String message) {
        CommonResponse<T> restResult = new CommonResponse<>(responseCodeEnum, message);
        return restResult;
    }

}
